package com.example.mobile2021606128wje0615;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class MySQLiteOpenHelper extends SQLiteOpenHelper {
    public MySQLiteOpenHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super( context, name, factory, version );
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql="create table users(_id integer primary key autoincrement,name varchar(20) not null,age integer,score float)";
        db.execSQL( sql );
        //初始化数据
        ContentValues values=new ContentValues();
        values.put( "name","王小平" );
        values.put( "age",19 );
        values.put( "score",88 );
        db.insert( "users",null,values );
        values.put( "name","王小丽" );
        values.put( "age",18 );
        values.put( "score",88 );
        db.insert( "users",null,values );
        values.put( "name","黄小华" );
        values.put( "age",20 );
        values.put( "score",88 );
        db.insert( "users",null,values );



    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
